package com.soker.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/popularRank.html").setViewName("popularRank");
        registry.addViewController("/space.html").setViewName("space");
        registry.addViewController("/history.html").setViewName("history");
        registry.addViewController("/tofollow.html").setViewName("to/tofollow");
        registry.addViewController("/tofollow1.html").setViewName("to/tofollow1");
        registry.addViewController("/tocontribute.html").setViewName("to/tocontribute");
        registry.addViewController("/tocollect.html").setViewName("to/tocollect");
        registry.addViewController("/tostate.html").setViewName("to/tostate");
        //user
        registry.addViewController("/login.html").setViewName("user/login");
        registry.addViewController("/register.html").setViewName("user/register");
        //fan
        registry.addViewController("/flist.html").setViewName("fan/flist");
        registry.addViewController("/fdesc.html").setViewName("fan/fdesc");
        registry.addViewController("/fdetail.html").setViewName("fan/fdetail");
        //video
        registry.addViewController("/food.html").setViewName("video/food");
        registry.addViewController("/foodplay.html").setViewName("video/foodplay");
        //navigation
        registry.addViewController("/navigation/navigationBar.html").setViewName("navigation/navigationBar");
        registry.addViewController("/navigation/header.html").setViewName("navigation/header");
        registry.addViewController("/navigation/collect.html").setViewName("navigation/collect");
        registry.addViewController("/navigation/contribute.html").setViewName("navigation/contribute");
        registry.addViewController("/navigation/follow.html").setViewName("navigation/follow");
        registry.addViewController("/navigation/state.html").setViewName("navigation/state");
    }

    //自定义的国际化组件生效
    @Bean
    public LocaleResolver localeResolver() {
        return new MyLocaleResolver();
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/index.html","/","/login.html","/register.html","/verifyPasswordByUsername","/register", "/navigation/**","/css/**", "/js/**", "/img/**",
                        "/s_img/**","/vimg/**");
    }
}
